package com.jt.controller;

import com.jt.annotation.RequiredLog;
import com.jt.pojo.Bill;
import com.jt.pojo.Item;
import com.jt.pojo.Repertory;
import com.jt.service.BillService;
import com.jt.vo.BillVO;
import com.jt.vo.PageResult;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("bill")
public class BillController {

    @Autowired
    private BillService billService;

    @GetMapping("/getBillList")
    public SysResult getBillList(PageResult pageResult){
        System.out.println(pageResult);
        pageResult=billService.getBilllist(pageResult);

        return SysResult.success(pageResult);
    }

    @DeleteMapping("/deleteBillById")
    @RequiredLog
    public SysResult deleteBillById(Integer id){
        billService.deleteBillById(id);
        return SysResult.success();

    }
    @PostMapping ("/addBill")
    @RequiredLog
    public SysResult addBill( @RequestBody Bill bill){
        billService.addBill(bill);
        System.out.println(bill);
        return SysResult.success();
    }
    @PutMapping("updateBill")
    @RequiredLog
    public SysResult updateBill(@RequestBody Bill bill){

        billService.updateBill(bill);
        return SysResult.success();
    }

    @GetMapping("/{id}")
    public SysResult getBillById(@PathVariable Integer id){
          Bill bill= billService.getBillById(id);
          return SysResult.success(bill);
    }
}
